import '../../base/beans/jcring_bean.dart';
import '../../config/network_config.dart';
import '../http/diohttp.dart';
import '../proxy/proxy_data.dart';

//服务器数据
class JcServerData extends DataProxy {
  static const _tag = '[jc_server_data.dart][JcServerData]';

  @override
  void init() {}

  @override
  Future<bool> saveWomanHealthData(
      String userToken,
      String periodStartTime,
      String periodTwoStartTime,
      int periodLenth,
      int period,
      int regularly,
      int tracking) async {
    var res = await DioHttp.getInstance()
        .post("/jcloud/wearableblev3/womenHealth/savePeriodInfo", {
      "userToken": userToken,
    }, {
      "periodStartTime": periodStartTime,
      "periodTwoStartTime": periodTwoStartTime,
      "periodLenth": periodLenth, //经期长度
      "period": period, //周期时长
      "regularly": regularly, //是否规律  1:规律，0：不规律
      "tracking": tracking //是否周期跟踪 1:周期跟踪，0：不跟踪
    });
    if (NetworkConfig.RESULT_STATUS_SUCCEED == res["code"]) {
      return true;
    } else {
      return false;
    }
  }

  @override
  Future<bool> saveHealthRecordData(
      String userToken,
      String day,
      int flowRate,
      int colorRate,
      int dysmenorrhea,
      List<int> symptoms,
      int leucorrhea,
      int mood,
      int ovulation,
      int love,
      String notes) async {
    var res = await DioHttp.getInstance()
        .post("/jcloud/wearableblev3/womenHealth/saveRecord", {
      "userToken": userToken,
    }, {
      "day": day,
      "flowRate": flowRate,
      "colorRate": colorRate,
      "dysmenorrhea": dysmenorrhea,
      "symptoms": symptoms,
      "leucorrhea": leucorrhea,
      "mood": mood,
      "ovulation": ovulation,
      "love": love,
      "notes": notes,
    });
    if (NetworkConfig.RESULT_STATUS_SUCCEED == res["code"]) {
      return true;
    } else {
      return false;
    }
  }

  @override
  Future<List<MenstrualRecord>> queryHealthRecordData(String userToken, String startDate, String endDate) async {
    List<MenstrualRecord> result = [];
    var res = await DioHttp.getInstance()
        .get("/jcloud/wearableblev3/womenHealth/queryRecord", {
      "userToken": userToken,
    }, {
      "startDay": startDate,
      "endDay": endDate,
    });
    if (NetworkConfig.RESULT_STATUS_SUCCEED == res["code"]) {
      result = (res["data"] as List<dynamic>)
          .map((item) => MenstrualRecord.fromJson(item as Map<String, dynamic>))
          .toList();
    }
    return result;
  }

  @override
  Future<Map<String, dynamic>> queryWomanHealthData(String userToken) async {
    var res = await DioHttp.getInstance()
        .get("/jcloud/wearableblev3/womenHealth/queryPeriodInfo", {
      "userToken": userToken,
    }, {});
    return res;
  }



}
